package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlLesson entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see idv.loveloser.dao.MdlLesson
 * @author MyEclipse Persistence Tools
 */

public class MdlLessonDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlLessonDAO.class);
	// property constants
	public static final String COURSE = "course";
	public static final String NAME = "name";
	public static final String PRACTICE = "practice";
	public static final String MODATTEMPTS = "modattempts";
	public static final String USEPASSWORD = "usepassword";
	public static final String PASSWORD = "password";
	public static final String DEPENDENCY = "dependency";
	public static final String CONDITIONS = "conditions";
	public static final String GRADE = "grade";
	public static final String CUSTOM = "custom";
	public static final String ONGOING = "ongoing";
	public static final String USEMAXGRADE = "usemaxgrade";
	public static final String MAXANSWERS = "maxanswers";
	public static final String MAXATTEMPTS = "maxattempts";
	public static final String REVIEW = "review";
	public static final String NEXTPAGEDEFAULT = "nextpagedefault";
	public static final String FEEDBACK = "feedback";
	public static final String MINQUESTIONS = "minquestions";
	public static final String MAXPAGES = "maxpages";
	public static final String TIMED = "timed";
	public static final String MAXTIME = "maxtime";
	public static final String RETAKE = "retake";
	public static final String ACTIVITYLINK = "activitylink";
	public static final String MEDIAFILE = "mediafile";
	public static final String MEDIAHEIGHT = "mediaheight";
	public static final String MEDIAWIDTH = "mediawidth";
	public static final String MEDIACLOSE = "mediaclose";
	public static final String SLIDESHOW = "slideshow";
	public static final String WIDTH = "width";
	public static final String HEIGHT = "height";
	public static final String BGCOLOR = "bgcolor";
	public static final String DISPLAYLEFT = "displayleft";
	public static final String DISPLAYLEFTIF = "displayleftif";
	public static final String PROGRESSBAR = "progressbar";
	public static final String HIGHSCORES = "highscores";
	public static final String MAXHIGHSCORES = "maxhighscores";
	public static final String AVAILABLE = "available";
	public static final String DEADLINE = "deadline";
	public static final String TIMEMODIFIED = "timemodified";

	public void save(MdlLesson transientInstance) {
		log.debug("saving MdlLesson instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(MdlLesson persistentInstance) {
		log.debug("deleting MdlLesson instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlLesson findById(java.lang.Long id) {
		log.debug("getting MdlLesson instance with id: " + id);
		try {
			MdlLesson instance = (MdlLesson) getSession().get(
					"idv.loveloser.dao.MdlLesson", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlLesson instance) {
		log.debug("finding MdlLesson instance by example");
		try {
			List results = getSession()
					.createCriteria("idv.loveloser.dao.MdlLesson")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlLesson instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from MdlLesson as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByCourse(Object course) {
		return findByProperty(COURSE, course);
	}

	public List findByName(Object name) {
		return findByProperty(NAME, name);
	}

	public List findByPractice(Object practice) {
		return findByProperty(PRACTICE, practice);
	}

	public List findByModattempts(Object modattempts) {
		return findByProperty(MODATTEMPTS, modattempts);
	}

	public List findByUsepassword(Object usepassword) {
		return findByProperty(USEPASSWORD, usepassword);
	}

	public List findByPassword(Object password) {
		return findByProperty(PASSWORD, password);
	}

	public List findByDependency(Object dependency) {
		return findByProperty(DEPENDENCY, dependency);
	}

	public List findByConditions(Object conditions) {
		return findByProperty(CONDITIONS, conditions);
	}

	public List findByGrade(Object grade) {
		return findByProperty(GRADE, grade);
	}

	public List findByCustom(Object custom) {
		return findByProperty(CUSTOM, custom);
	}

	public List findByOngoing(Object ongoing) {
		return findByProperty(ONGOING, ongoing);
	}

	public List findByUsemaxgrade(Object usemaxgrade) {
		return findByProperty(USEMAXGRADE, usemaxgrade);
	}

	public List findByMaxanswers(Object maxanswers) {
		return findByProperty(MAXANSWERS, maxanswers);
	}

	public List findByMaxattempts(Object maxattempts) {
		return findByProperty(MAXATTEMPTS, maxattempts);
	}

	public List findByReview(Object review) {
		return findByProperty(REVIEW, review);
	}

	public List findByNextpagedefault(Object nextpagedefault) {
		return findByProperty(NEXTPAGEDEFAULT, nextpagedefault);
	}

	public List findByFeedback(Object feedback) {
		return findByProperty(FEEDBACK, feedback);
	}

	public List findByMinquestions(Object minquestions) {
		return findByProperty(MINQUESTIONS, minquestions);
	}

	public List findByMaxpages(Object maxpages) {
		return findByProperty(MAXPAGES, maxpages);
	}

	public List findByTimed(Object timed) {
		return findByProperty(TIMED, timed);
	}

	public List findByMaxtime(Object maxtime) {
		return findByProperty(MAXTIME, maxtime);
	}

	public List findByRetake(Object retake) {
		return findByProperty(RETAKE, retake);
	}

	public List findByActivitylink(Object activitylink) {
		return findByProperty(ACTIVITYLINK, activitylink);
	}

	public List findByMediafile(Object mediafile) {
		return findByProperty(MEDIAFILE, mediafile);
	}

	public List findByMediaheight(Object mediaheight) {
		return findByProperty(MEDIAHEIGHT, mediaheight);
	}

	public List findByMediawidth(Object mediawidth) {
		return findByProperty(MEDIAWIDTH, mediawidth);
	}

	public List findByMediaclose(Object mediaclose) {
		return findByProperty(MEDIACLOSE, mediaclose);
	}

	public List findBySlideshow(Object slideshow) {
		return findByProperty(SLIDESHOW, slideshow);
	}

	public List findByWidth(Object width) {
		return findByProperty(WIDTH, width);
	}

	public List findByHeight(Object height) {
		return findByProperty(HEIGHT, height);
	}

	public List findByBgcolor(Object bgcolor) {
		return findByProperty(BGCOLOR, bgcolor);
	}

	public List findByDisplayleft(Object displayleft) {
		return findByProperty(DISPLAYLEFT, displayleft);
	}

	public List findByDisplayleftif(Object displayleftif) {
		return findByProperty(DISPLAYLEFTIF, displayleftif);
	}

	public List findByProgressbar(Object progressbar) {
		return findByProperty(PROGRESSBAR, progressbar);
	}

	public List findByHighscores(Object highscores) {
		return findByProperty(HIGHSCORES, highscores);
	}

	public List findByMaxhighscores(Object maxhighscores) {
		return findByProperty(MAXHIGHSCORES, maxhighscores);
	}

	public List findByAvailable(Object available) {
		return findByProperty(AVAILABLE, available);
	}

	public List findByDeadline(Object deadline) {
		return findByProperty(DEADLINE, deadline);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findAll() {
		log.debug("finding all MdlLesson instances");
		try {
			String queryString = "from MdlLesson";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlLesson merge(MdlLesson detachedInstance) {
		log.debug("merging MdlLesson instance");
		try {
			MdlLesson result = (MdlLesson) getSession().merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(MdlLesson instance) {
		log.debug("attaching dirty MdlLesson instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlLesson instance) {
		log.debug("attaching clean MdlLesson instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}